package acceptanceTests.readingAmessage;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.net.Socket;
import server.ForumServer;
import server.WSEPHandler;

public class ReadingAmessageImp implements ReadingAmessageInt {
	private boolean _implementedGetLegalPathToMessage  = true;
	private boolean _implementedGetMessagePath  = true;
	private boolean _implementedGetUserType  = false;
	private boolean _implementedGoToMessage  = true;
	private boolean _implementedGoToPath  = false;
	private boolean _implementedReadMessage  = false;

	private ForumServer _server;
	private WSEPHandler _handler;
	
	public ReadingAmessageImp(ForumServer server){
		this._server = server;
		try{
			Socket s= new Socket("localhost", getPort());
			_handler= new WSEPHandler(s,server);
		}
		catch(IOException e){
		
		}
	}
	
	private static int getPort() {
		String str="0";
		try {
	        BufferedReader in = new BufferedReader(new FileReader("port.txt"));
	        str = in.readLine();
	        in.close();
	    } catch (IOException e) {
	    }
		return Integer.parseInt(str);
	}

	public String getIllegalPathForUser(int userType) {
		// TODO Auto-generated method stub
		System.out.println("not yet implemented");
		return null;
	}


	public String getLegalPathToMessage() {

		_handler.getRootTopic();
		_handler.setCurrentlyViewedItem(_server.getDataRepository().getRootTopic());
		_handler.getItem(1);
		return _handler.get_currentlyViewedItem().toString();
	}


	public String getMessagePath(Object message) {
		
		return message.toString();
	}


	public int getNumberOfUnreadMessage(String userName) {
		// TODO Auto-generated method stub
		System.out.println("not yet implemented");
		return 0;
	}


	public int getNumberOfViewingOnMessage(Object o) {
		// TODO Auto-generated method stub
		System.out.println("not yet implemented");
		return 0;
	}


	public Object getUnreadMessage(String userName) {
		// TODO Auto-generated method stub
		System.out.println("not yet implemented");
		return null;
	}

	public int getUserType(String userName) {
		// TODO Auto-generated method stub
		System.out.println("not yet implemented");
		return 0;
	}


	public Object goToMessage(String path, int userType) {

		return _handler.get_currentlyViewedItem().toString();
	}

	public boolean goToPath(String path, int userType) {
		// TODO Auto-generated method stub
		System.out.println("not yet implemented");
		return false;
	}

	public boolean hasUnreadMessage(String userName) {
		// TODO Auto-generated method stub
		System.out.println("not yet implemented");
		return false;
	}


	public boolean isUnreadMessage(Object o, String userName) {
		// TODO Auto-generated method stub
		System.out.println("not yet implemented");
		return false;
	}


	public boolean readMessage(Object o, String userName) {
		// TODO Auto-generated method stub
		return false;
	}


	public boolean is_implementedGetLegalPathToMessage() {
		return _implementedGetLegalPathToMessage;
	}

	public void set_implementedGetLegalPathToMessage(boolean getLegalPathToMessage) {
		_implementedGetLegalPathToMessage = getLegalPathToMessage;
	}

	public boolean is_implementedGetMessagePath() {
		return _implementedGetMessagePath;
	}

	public void set_implementedGetMessagePath(boolean getMessagePath) {
		_implementedGetMessagePath = getMessagePath;
	}

	public boolean is_implementedGetUserType() {
		return _implementedGetUserType;
	}

	public void set_implementedGetUserType(boolean getUserType) {
		_implementedGetUserType = getUserType;
	}

	public boolean is_implementedGoToMessage() {
		return _implementedGoToMessage;
	}

	public void set_implementedGoToMessage(boolean goToMessage) {
		_implementedGoToMessage = goToMessage;
	}

	public boolean is_implementedGoToPath() {
		return _implementedGoToPath;
	}

	public void set_implementedGoToPath(boolean goToPath) {
		_implementedGoToPath = goToPath;
	}

	public boolean is_implementedReadMessage() {
		return _implementedReadMessage;
	}

	public void set_implementedReadMessage(boolean readMessage) {
		_implementedReadMessage = readMessage;
	}

	public Object goToMessage(String path) {
		return _handler.get_currentlyViewedItem();
	}

}
